#include "head.h"

bool sign_up(int net_fd){
	fprintf(stdout,"%s\n","在注册");
	char userName[1024];
	recv(net_fd,userName,sizeof(userName),0);
	char nowPath[1021];
	if(getcwd(nowPath,sizeof(nowPath)) == NULL){
		perror("getcwd error : ");
		//写入问题日志中
		exit(1);
	}
	printf("cwd = %s\n",nowPath);
	//char Path[1024];
	//snprintf(Path,sizeof(Path),"%s/..",nowPath);
	DIR* dir = opendir(nowPath);
	struct dirent* dirs;
	bool isUsername = false;
	while(isUsername != true){// 判断用户名是否可以用
		while((dirs = readdir(dir)) != NULL){
			printf("%s\n",dirs->d_name);
			if(strcmp(userName,dirs->d_name) == 0){
				send(net_fd,&isUsername,sizeof(isUsername),0);
				break;
			}
		}
		if(dirs == NULL){isUsername = true;}
		else{recv(net_fd,userName,sizeof(userName),0);}
	}
	send(net_fd,&isUsername,sizeof(isUsername),0);
	char password[1024];
	recv(net_fd,password,sizeof(password),0);
	// 存入数据库
	char userPath[2048];
	snprintf(userPath,sizeof(userPath),"%s/%s",nowPath,userName);
	printf("userPath = %s\n",userPath);
	if(mkdir(userPath,0777) == -1){
		perror("mkdir fail : ");
		closedir(dir);
		return false;
	}
	closedir(dir);
	return true;
}
//bool sign_in();

